//UART_routines.c
#include "UART_routines.h"


//Inicializacion UART0
//baud rate: 57200  clock = 12MHz

void uart0_init(void)
{
 UBRR0H = 0x00;
 UBRR0L = 0x0C;
 UCSR0B = (1<<RXEN0)|(1<<TXEN0);
 UCSR0C = (1<<USBS0)|(3<<UCSZ00);

}

//Funcion para recibir un Byte
unsigned char receiveByte( void )
{
    unsigned char data;
	while(!(UCSR0A & (1<<RXC0)));
	data = UDR0;
	return(data);
}

//Funcion para transmitir un Byte
void transmitByte( unsigned char data )
{
	while ( !(UCSR0A & (1<<UDRE0)) ); /* Espera final de transmision anterior */
	UDR0 = data;

}

//Funcion para transmitir cadena caracteres
void transmitString(unsigned char* string)
{
  while (*string){
   transmitByte(*string++);
  _delay_ms(2);
  }
}
//Funcion para transmitir cadenas en flash
void transmitString_F(char* string)
{
  while (pgm_read_byte(&(*string)))
   transmitByte(pgm_read_byte(&(*string++)));
}

